package org.grow.took.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.grow.took.dao.PlayerDao;
import org.grow.took.entity.PagedResults;
import org.grow.took.entity.Player;
import org.grow.took.entity.PlayerQueryCondition;
import org.grow.took.entity.PlayerSearchFrom;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: xwg
 * @CreateDate: 2021/9/10
 */

@RestController
@RequestMapping("/ceto/player")
public class PlayerController {
    @Autowired
    private PlayerDao playerDao;

    @PostMapping("/query")
    public PagedResults<Player> query(@RequestBody PlayerSearchFrom playerSearchFrom){
        Integer pageSize = playerSearchFrom.getPageSize();
        Integer pageNum = playerSearchFrom.getPageNum();
        PlayerQueryCondition qc = playerSearchFrom.getQueryCondition();
        IPage<Player> page = new Page(pageNum,pageSize);
        IPage<Player> playerIPage = playerDao.dynamicQuery(page, qc);


        PagedResults<Player> pagedResults = new PagedResults<>();
        List<Player> records = playerIPage.getRecords();
        long total = playerIPage.getTotal();
        pagedResults.setResults(records);
        pagedResults.setTotal(total);

        return pagedResults;
    }
}
